<?php

$doc = new DOMDocument("1.0","utf-8");

$root = $doc->appendChild($doc->createElement("root"));

$table = $root->appendChild($doc->createElement("product"));

$arr = array(
	"1" => "Tuan",
	"2"	=> "Minh",
	"3"	=> "Hung",
	"4" => "khung"
);

foreach($arr as $key => $value){

	$item = $table->appendChild($doc->createElement($value));
	$item->setAttribute('attr1', 'attrval1');
	$item->setAttribute('key',"hello");
	$value = $item->appendChild($doc->createTextNode($key));
}

$xml_string = $doc->saveXML();
header("Content-Type: text/xml");
echo $xml_string;